<?php


namespace app\controller;

use app\BaseController;
use app\model\DeliveryModel;
use think\facade\Db;
class Index extends BaseController
{
    /**
     * @return |null
     * @notes
     * @author: dongdong
     * @date: 2024/12/23 15:05
     */
    public function index(){
        return null;
    }

    /**
     * @notes size_vehicle
     * @author: dongdong
     * @date: 2024/12/28 14:36
     */
    public function size_vehicle(){
        $a = Db::table("store_size")->where("transport_way=5")->select();
        $b = Db::table("store_vehicle")->where("transport_way=5")->select();
        foreach ($a as $k =>&$v){
            foreach ($b as $kk =>&$vv){
                Db::table("store_size_vehicle")->insert(['size_id'=>$v['id'],'vehicle_id'=>$vv['id']]);
            }
        }
        echo 1;
    }


    public function test(){
        $list = Db::table("store_route")->select();
        foreach ($list as $k =>&$v){
            $id = $v['id'];
            $area_id = $v['area_id'];
            if($area_id){
                $area = Db::connect('fast_mysql')->table("fa_area")->field("id,pid,country")->where("id=$area_id")->find();
                if($area){
                    $pid = $area['pid'];
                    $country = $area['country'];
                    Db::table("store_route")->where(["id"=>$v['id']])->update(['province_id'=>$pid,'country'=>$country]);
                }
            }
        }
    }


    public function test2(){
        //$delivery_model = new DeliveryModel();
        //$delivery_model->route_list(30,1);
        echo $this->generateUniqueSerialNumber();
    }

    function generateUniqueSerialNumber($length = 32) {
        $timestamp = time(); // 当前时间戳
        $randomNumber = mt_rand(0, 999999999); // 生成一个9位的随机数
        $serialNumber = $timestamp . sprintf("%09d", $randomNumber); // 时间戳后补0

        // 如果流水号长度不足32位，则在前面填充0
        return str_pad($serialNumber, $length, "0", STR_PAD_LEFT);
    }
}